package com.springboot.sba.D4_Servlet;


import org.springframework.core.annotation.Order;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

@Order(1)
@WebFilter(urlPatterns = "/filter/*", filterName = "filterTest")
public class FilterTest implements Filter {
    //写业务代码
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("____________filter  doFilter______________");
        String name = request.getParameter("name");
        if ("zzz".equals(name)) {
            filterChain.doFilter(request, response);
        } else {
            return;
        }
    }

    //filter对象只会创建一次，init方法也只会执行一次。
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("____________filter  init______________");
    }

    //在销毁Filter时自动调用。
    public void destroy() {
        System.out.println("____________filter  destroy______________");
    }
}
